window.addEventListener('DOMContentLoaded', () => {
    var os = require("os");
    if(os.networkInterfaces().WLAN){
      sessionStorage.mac = os.networkInterfaces().WLAN[0].mac
    }else if(sessionStorage.mac = os.networkInterfaces()['以太网']){
      sessionStorage.mac = os.networkInterfaces()['以太网'][0].mac
    }else if(sessionStorage.mac = os.networkInterfaces()['en0']){
      sessionStorage.mac = os.networkInterfaces()['en0'][0].mac
    } 
    sessionStorage.name = os.hostname()
    // console.log(sessionStorage.getItem('mac'))
    // console.log(sessionStorage.getItem('name')) 

    const replaceText = (selector, text) => {
    const element = document.getElementById(selector)
        if (element) element.innerText = text
    }
    // console.log(process.versions);
    console.log(process.cwd());
    console.log(__dirname)
    for (const type of ['chrome', 'node', 'electron']) {
        replaceText(`${type}-version`, process.versions[type])
        // console.log(process.versions[type])
        sessionStorage[`${type}-version`]= process.versions[type];
    }  


    })
    
//向渲染器进程暴露一个全局的 window.electronAPI 变量。
const { app,contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
  // getAppInfo: (callback) => ipcRenderer.on('getAppInfo', callback)
  // getAppInfo: (callback) => ipcRenderer.send('getAppInfo', callback)
  reloadApp:()=>ipcRenderer.invoke('reloadApp'),
  reloadWin:()=>ipcRenderer.invoke('reloadWin'),
  clearCache:()=>ipcRenderer.invoke('clearCache'),
  base:()=> {if(process.env.NODE_ENV=='development'){return ''} else {return __dirname.replace("dist-electron","dist")}},
  getWinInfo: () => ipcRenderer.invoke('win:info'),
  getAppInfo: () => ipcRenderer.invoke('app:info'),
  setUserInfo: (param) => ipcRenderer.send('user:set',param),
  setLicense: (param) => ipcRenderer.send('license:set',param),
  getLicenseInfo: () => ipcRenderer.invoke('license:info'),
  getUserInfo: () => ipcRenderer.invoke('user:info'),
  checkForUpdates:()=>ipcRenderer.send('checkForUpdates'),
  downLoadUpdate:()=>ipcRenderer.send('downLoadUpdate'),
  downloadProgress: (callback) => ipcRenderer.on('downloadProgress', callback),
  uploadMessage: (callback) => ipcRenderer.on('uploadMessage', callback),
  getFilePathInfo: (param,callback) => ipcRenderer.invoke('filePath:info',param,callback),
  getTempFilePath: () => ipcRenderer.invoke('getTempFilePath'),
  getLocalProject: () => ipcRenderer.invoke('getLocalProject'),
  getLocalServer: () => ipcRenderer.invoke('getLocalServer'),
  getTempFilePathInfo: (param,callback) => ipcRenderer.invoke('tempFilePath:info',param,callback),
  setTempFilePathInfo: (path,param) => ipcRenderer.send('tempFilePath:set',path,param),
  setNativeTheme: (param) => ipcRenderer.send('nativeTheme:set',param),
  offlineProject: (param) => ipcRenderer.invoke('downloadOffline',param),
  getNetworkStatus: (callback) => ipcRenderer.on('getNetworkStatus', callback), 
  checkNetwork: (param) => ipcRenderer.invoke('checkNetwork', param), 
  onWinChangeEvent: (callback) => ipcRenderer.on('winChangeEvent', callback),
  openExternal: (param) => ipcRenderer.send('openExternal',param),

 })